<template>
  <div>
 

      <div v-if="username==''">


        <router-link to="/login">登录</router-link>

        /

        <router-link to="/reg">注册</router-link>
        

      </div>


      <div>
        
          欢迎您，尊贵的{{ change_type(type) }} 用户:  {{ username }}


          <van-button @click="logout">登出</van-button>


      </div>



   
  </div>
</template>

<script>

export default {
 data() {
    return {

      username:"",
      type:0
     
    }
  },
  methods:{

    logout:function(){


          localStorage.removeItem("username");
          localStorage.removeItem("id");
          localStorage.removeItem("token");
          localStorage.removeItem("type");


          this.$router.push("/login");


    },
    //替换类别
    change_type:function(val){


        if(val === "1"){

            return "商户后台";

        }else if(val === "2"){

            return "运营后台";

        }else{

            return "流量后台";
        }



    }

    

  },

  mounted(){

      //判断是否登录
      if(localStorage.getItem("username") === null){

            this.username = "";

      }else{


          this.username = localStorage.getItem("username");

          this.type = localStorage.getItem("type");

      }


       // this.myaxios("https://localhost/","get").then(data =>{

       //    console.log(data);



       //  });

    

  }

}
</script>


<style scoped>
  @import url("../assets/style.css");


</style>

